/*
 * 文件名               :  ByteArrayConnectHandler.java
 * 用途                    :  当根据Id无法找到对象时,本Handler会新建一个合格的对象,并将其加入Finder中
 * 最后修改日期:  $LastChangedDate: 2009-09-14 13:13:18 +0000 (Mon, 14 Sep 2009) $
 * 最后修改者     :  $LastChangedBy: wendal1985@gmail.com $
 * 创建者               :  Wendal Chen <wendal1985@gmail.com>
 */
package com.wendal.java.preproxy.bridge;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.wendal.java.preproxy.client.ClientConfig;
import com.wendal.java.preproxy.server.SocketHandlerFinder;
import com.wendal.java.preproxy.thread.SocketHandler;

public class ByteArrayConnectHandler implements ByteArrayHandler {
	
	private Log log = LogFactory.getLog(getClass());
	

	@Override
	public void handle(String id, SocketHandlerFinder outputFinder) {
		
		try {
			Socket localSocket = new Socket("127.0.0.1",Integer.parseInt(ClientConfig.localPort));
			new SocketHandler(BridgeConnector.getDefaultBridgeConnector(),outputFinder,localSocket,id).start();
			log.info("新建一个Socket, id= "+ id);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
